package com.xn.myyxcampus.utils;

import java.util.Stack;


import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;

/**
 * activity ������
 * @author Doom
 *
 */
public class ActivityUtils {
	private static Stack<Activity> activityStack ;
	private static ActivityUtils activityUtils;
	
	public static ActivityUtils getActivityUtilsInstance(){
		if(activityUtils==null){
			activityUtils = new ActivityUtils();
		}
		return activityUtils;
	}
	
	public static void addToActivityStack(Activity activity){
		if(activityStack==null){
			activityStack = new Stack<Activity>();
		}
		activityStack.add(activity);
	}
	
	/**
	 * 结束所有Activity
	 */
	public static void finishAllActivity(){
		for (int i = 0, size = activityStack.size(); i < size; i++){
            if (null != activityStack.get(i)){
            	activityStack.get(i).finish();
            }
	    }
		activityStack.clear();
	}
	
	/**
	 * 结束指定的Activity
	 */
	public static void finishActivity(Activity activity){
		if(activity!=null){
			activityStack.remove(activity);
			activity.finish();
			activity=null;
		}
	}
	
	/**
	 * 退出应用程序
	 */
	public static void AppExit(Context context) {
		try {
			finishAllActivity();
			android.os.Process.killProcess(android.os.Process.myPid());
		} catch (Exception e) {	}
	}
}
